<!DOCTYPE html>
<html>
<head>
    <title>$app.topic 用户管理</title>
    #parse("/inc/meta.htm")
</head>
<body id="inner_page_start">

#parse("/inc/header.htm")

<div id="wrapper">

    #parse("/inc/menu.htm")

    <div id="content-wrapper">

        <div class="container-fluid">

            <!-- 面包屑-->
            <ol class="breadcrumb">
                <li class="breadcrumb-item">
                    用户管理
                </li>
                <li class="breadcrumb-item active">用户列表</li>
            </ol>

            <div class="card mb-3">
                <div class="card-header">
                    <i class="fas fa-table"></i>
                    后台管理用户浏览</div>


                <div class="card-body">
                    <form id="list_form" action="/users/page" >
                        <input type="hidden" name="page"  id="list_page" value="$respData.pagenumber" />

                        <div class="form-inline">
                            <div class="form-group mx-sm-3">
                                <label>姓名:
                                    <input type="search" class="form-control form-control-sm" name="uname"
                                           value="$!form.uname" />
                                </label>

                            </div>
                            <div class="form-group mx-sm-3">
                                <label>手机号码:
                                    <input type="search" class="form-control form-control-sm" name="tel"
                                           value="$!form.tel" />
                                </label>

                            </div>
                            <div class="form-group mx-sm-3">
                                <label>状态:
                                    <select name="state" aria-controls="dataTable"
                                            class="custom-select custom-select-sm form-control form-control-sm">
                                        <option value="" >全部</option>
                                        <option value="1" #if($!form.state ==1 ) selected #end >禁用</option>
                                        <option value="0" #if($!form.state ==0 ) selected #end >正常</option>
                                    </select>
                                </label>
                            </div>

                            <div class="form-group mx-sm-3">
                                <div class="dataTables_filter float-right">
                                    <button class="btn btn-primary"  onclick="jump('list_form',1)">搜索</button>
                                </div>
                            </div>
                        </div>
                        <br>
                        <div class="form-inline">
                            <div class="form-group mx-sm-3">
                                <label>管理:
                                    <select name="pid" aria-controls="dataTable"
                                            class="custom-select custom-select-sm form-control form-control-sm">
                                        <option value="" >全部</option>
                                        #foreach( $puser in ${pusers} )
                                        <option value="$puser.id" #if($!form.pid ==$puser.id ) selected #end >$!puser.uname</option>
                                        #end
                                    </select>
                                </label>
                            </div>
                            <div class="form-group mx-sm-3">
                                <label>角色:
                                    <select name="role" aria-controls="dataTable"
                                            class="custom-select custom-select-sm form-control form-control-sm">
                                        <option value="" >全部</option>
                                        #foreach( $role in ${roles} )
                                        <option value="$role.role" #if($!form.role ==$role.role) selected #end>$role.gname</option>
                                        #end
                                    </select>
                                </label>
                            </div>

                            <div class="form-group mx-sm-3">
                                 <a href="/users/user" class="btn btn-primary"> 新建用户</a>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-sm-12 col-md-12"  >
                                <div class="form-inline float-right">
                                    <label>显示
                                        <select name="rows"  onchange="submit()"  class="form-control">
                                            <option value="10" #if($respData.pagerow == 10) selected #end>10</option>
                                            <option value="15" #if($respData.pagerow == 15) selected #end>15</option>
                                            <option value="20" #if($respData.pagerow == 20) selected #end>20</option>
                                            <option value="25" #if($respData.pagerow == 25) selected #end>25</option>
                                        </select>
                                        行</label>
                                </div>
                            </div>
                        </div>


                        <div class="row">
                            <div class="col-sm-12 table-outer-box">
                                <table class="table table-bordered dataTable" id="dataTable" width="100%" cellspacing="0" role="grid" aria-describedby="dataTable_info" style="width: 100%;">
                                    <thead>
                                    <tr role="row">
                                        <th>姓名</th>
                                        <th>电话</th>
                                        <th>上级</th>
                                        <th>状态</th>
                                        <th>角色</th>
                                        <th>渠道码</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    #foreach( $row in ${respData.getRows()} )
                                    <tr>
                                        <td>$!row.uname</td>
                                        <td>$!row.tel</td>
                                        <td>$!row.pname</td>
                                        <td>#if($!row.state==0 ) 正常
                                            <button class="btn btn-danger btn-sm" onclick="userState($row.id,1);">禁用</button>
                                            #else 禁用
                                            <button class="btn btn-primary btn-sm" onclick="userState($row.id,0);">启用</button>
                                            #end</td>
                                        <td>$!row.gname</td>
                                        <td>$!row.qcode</td>
                                        <td>
                                            <a class="btn btn-primary btn-sm" href="/users/user?id=$row.id">编辑</a>
                                        </td>
                                    </tr>
                                    #end
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-12 col-md-5">
                                <div class="dataTables_info" id="dataTable_info" role="status" aria-live="polite">
                                    显示 $!respData.s 到 $!respData.e 一共 $!respData.total 条
                                </div>
                            </div>
                            <div class="col-sm-12 col-md-7">
                                <div class="dataTables_paginate paging_simple_numbers" id="dataTable_paginate">
                                    <ul class="pagination float-right">
                                        #page("/users/page?rows=$!respData.1" $respData )
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>
        <!-- /.container-fluid -->
        #parse("/inc/copyright.htm")
    </div>
    <!-- /.content-wrapper -->
</div>

#parse("/inc/footer.htm")
<script>
    function userState(uid, state) {
        $.ajax({
            url: "/users/upstate",
            data: { id:uid,state:state },
            type: "POST",
            dataType: "json",
            async: false,
            success: function(data) {
                // if(data.state == "000")
                //     console.log("success")
                jump('list_form')
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert("网络异常，请稍后重试")
            }
        });
    }
</script>
</body>
</html>